home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / cbm / 2273 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.2 KB

  1. Path: mail2news.demon.co.uk!insosf1.netins.net
  2. From: Alan Jones <alan.jones@qcs.org>
  3. Newsgroups: comp.sys.cbm
  4. Subject: Commodore Arithmetic
  5. Date: Wed,  7 Feb 1996 11:43:00 GMT
  6. Organization: Quad-cities Computer Society
  7. Message-ID: <96020719151143766@qcs.org>
  8. X-NNTP-Posting-Host: insosf1.netins.net
  9. X-Mail2News-Path: insosf1.netins.net
  10.  
  11.  
  12. Recently, the C64/128 floating point arithmetic has been maligned
  13. here.  The C64/128 has good floating point math.  It uses 5 byte reals
  14. with a 4 byte (32 bit) mantissa.  There are no bugs in the basic FP
  15. arithmetic.  The reals ARE limited in range and precision.  They are
  16. more useful than compters using 32 bit reals, but not up to IEEE
  17. standard arithmetic.  IEEE FP arithmetic (double and extended
  18. precision...) would be much slower than our existing FP routines.  Of
  19. course it might be possible to interface a hardware FPU to the new
  20. Super64/128CPU (65816).
  21.  
  22. The other C64/128 FP routines, such as SIN, EXP, and functions that use
  23. them are not accurate to full 32 bit FP precision.  When used with
  24. care, they are often accurate enough for engineering work.
  25.  
  26. The most annoying inaccuracy may be the conversion between binary FP
  27. and decimal for I/O.  BASIC only prints 9 decimal digits of a FP
  28. number, but our binary FP number has about 9.6 decimal digits of
  29. precision.  What you see is not what you have!  Of course there are
  30. some simple tricks that you can use to print the FP number with more
  31. decimal precision, and you could do I/O using HEX notation.  If you
  32. save intermediate results for later use, make sure you write the FP
  33. values as binary rather than ASCII (converted to decimal).
  34.  
  35. If you do accounting type stuff with dollars and cents, using binary FP
  36. with its limited precision and rounding can be anoying.  If your
  37. results are off one penny, all of your work will be suspect.  Our 6502
  38. family of CPUs also has decimal arithmetic.  It can do decimal
  39. arithmetic exactly, although you may have to program it yourself.  I
  40. think the Paperclip word Processor will do simple calculations with up
  41. to 40 decimal digits of precision.
  42.  
  43. If you are using 64+ bit FP you can compute some things in a fast and
  44. sloppy manner.  Some programs that work OK on an IBM PC or workstation
  45. need more careful attention when coded for a C64/128.
  46.  
  47. Some numbers can not be represented exactly in binary FP formats of any
  48. precision.  If you want to calculate:
  49.  
  50.   a:=(1/3)*(1/5)*(1/7)*(1/11)
  51.  
  52. You should code it as:
  53.  
  54.   a:=1/(3*5*7*11)
  55.  
  56. Asside from being faster, it is more accurate.
  57.  
  58. There are many tips for preserving numerical accuracy in computations.
  59. There are often interesting tradoffs between computation speed, memory
  60. usage, and accuracy and stability.  There are even some C64/128
  61. specific tips.  (e.g. we usually store a real value in 5 bytes of
  62. memory but push it onto a stack as 6 bytes when we want to use it.)
  63.  
  64. This is not intended to be a Commodore FP tutorial.  It is reminder
  65. that the C64/128 can be used for "heavy math", and there are no bugs
  66. in the Commodore +, -, *, /, Floating Point arithmetic routines.  It
  67. uses 32 binary bit mantisa FP reals with proper rounding.
  68. Simple examples can always be contrived to demonstrate a perceived FP
  69. bug by computer illiterates(?).
  70.  
  71. alan.jones@qcs.org
  72.  
  73. ___ QWKRR128 V4.32 [R]
  74.